export { }

const myTime = (data?: Date | string): string => {
  if (!data) data = new Date()
  if (typeof data === 'string') data = new Date(data)
  const h = data.getHours()
  const m = data.getMinutes()
  const s = data.getSeconds()
  return `${h}-${m}-${s}`
}

type Data = {
  count: number
  time: string
}

type List = Array<Data>

const KEY: string = 'myTsTime'

const getData = (): List => {
  const arrStr = localStorage.getItem(KEY) || '[]'
  return JSON.parse(arrStr)
}

const setData = (): void => {
  const list = getData()

  list.push({
    count: list[list.length - 1] ? list[list.length - 1].count + 1 : 1,
    time: myTime()
  })


  localStorage.setItem(KEY, JSON.stringify(list))
}

const renderer = (): void => {
  setData()
  const app = document.querySelector('#app') as HTMLDivElement
  const dataList = getData()
  app.innerHTML = dataList.map(item => `次数：${item.count}--时间${item.time}`).join('</br>')
}
renderer()